<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
function getInitializer() {
    return {
        candidate: 'foo',
        sdpMid:'bar',
        sdpMLineIndex: 6
    };
}

test(function() {
    let candidate = new RTCIceCandidate(getInitializer());
    assert_equals(candidate.candidate, 'foo');
    assert_equals(candidate.sdpMid, 'bar');
    assert_equals(candidate.sdpMLineIndex, 6);

    const initializer = JSON.parse(JSON.stringify(candidate));
    candidate = new RTCIceCandidate(initializer);
    assert_equals(candidate.candidate, 'foo');
    assert_equals(candidate.sdpMid, 'bar');
    assert_equals(candidate.sdpMLineIndex, 6);
}, 'Constructor can be initialized with output from another constructor');

test(function() {
    assert_throws_js(TypeError, () => new RTCIceCandidate({}));
    assert_throws_js(TypeError, () => new RTCIceCandidate(5));
    assert_throws_js(TypeError, () => new RTCIceCandidate('foobar'));
    assert_throws_js(TypeError, () => new RTCIceCandidate({candidate: ''}));
}, 'Constructor throws on invalid input');

test(function() {
    new RTCIceCandidate({candidate: 'x', sdpMid: ''});
    new RTCIceCandidate({sdpMid: ''});
}, 'Constructor does not throw on valid input');

test(function() {
    const candidate = new RTCIceCandidate(getInitializer());
    candidate.candidate = 'bar';
    candidate.sdpMid = 'foo';
    candidate.sdpMLineIndex = 1;
    assert_equals(candidate.candidate, 'foo');
    assert_equals(candidate.sdpMid, 'bar');
    assert_equals(candidate.sdpMLineIndex, 6);
}, 'candidate, sdpMid, and sdpMLineIndex properties are read only');
</script>
</body>
</html>
